package com.example.reactor.reactor;

import java.util.function.Consumer;

public class MySubscriber<T> implements Subscriber<T> {
    private final Consumer<T> onNextAction;
    private final Runnable onCompleteAction;
    private final Consumer<Throwable> onErrorAction;

    public MySubscriber(Consumer<T> onNextAction, Runnable onCompleteAction, Consumer<Throwable> onErrorAction) {
        this.onNextAction = onNextAction;
        this.onCompleteAction = onCompleteAction;
        this.onErrorAction = onErrorAction;
    }

    @Override
    public void onNext(T value) {
        onNextAction.accept(value);
    }

    @Override
    public void onComplete() {
        onCompleteAction.run();
    }

    @Override
    public void onError(Throwable t) {
        onErrorAction.accept(t);
    }
}